package com.bcxj.serviceverificationcode.controller;

import com.bcxj.internalcommon.dto.ResponseResult;
import com.bcxj.internalcommon.response.NumberCodeResponse;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: NumberCodeController
 * Package: com.bcxj.controller
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/9/15 10:17
 * @Version 1.0
 * @Since 1.0
 */
@RestController
public class NumberCodeController {

    /**
     * 获取数字验证码
     * @param size 返回验证码的长度
     * @return
     */
    @GetMapping("numberCode/{size}")
    public ResponseResult<NumberCodeResponse> numberCode(@PathVariable Integer size) {
        double v = (Math.random() + 1) * (Math.pow(10, size - 1));
        int numberCode = (int) v;
        System.out.println("数字验证码服务生成的随机的验证码为：" + numberCode);


        NumberCodeResponse numberCodeResponse = new NumberCodeResponse(numberCode + "");
        System.out.println(numberCodeResponse);
        return ResponseResult.success(numberCodeResponse);
    }
}
